package cn.brian.modular.framework.drools.component;

import cn.brian.modular.framework.drools.utils.ScheduledThreadPoolExecutorUtil;

import java.util.concurrent.TimeUnit;

/**
 * @author
 * @date 2019/9/27 10:34
 * @since 1.0.0
 */

public class KieSchedule {

    private KieTemplate kieTemplate;

    public KieSchedule(KieTemplate kieTemplate) {
        this.kieTemplate = kieTemplate;
    }

    public void execute() {
        Long update = kieTemplate.getUpdate();
        if (update == null || update == 0L) {
            update = 30L;
        }
        ScheduledThreadPoolExecutorUtil.RULE_SCHEDULE.
                scheduleAtFixedRate(new RuleCache(kieTemplate),
                        1, update, TimeUnit.SECONDS);
    }


}
